package simplefactory

import "fmt"

func NewAPI(t int) API {
	if t == 1 {
		return &hiAPI{}
	} else if t == 2 {
		return &helloAPI{}
	}
	return nil
}


type API interface { // 接口
	Say(name string) string
}


type hiAPI struct{} // 实现 1

func (*hiAPI) Say(name string) string {
	return fmt.Sprintf("Hi, %s", name)
}


type helloAPI struct{} // 实现 2

func (*helloAPI) Say(name string) string {
	return fmt.Sprintf("Hello, %s", name)
}
